trigger:
  batch: true
  branches:
    include:
    - main
  paths:
    include:
    - '*'
    - src/libraries/System.Private.CoreLib/*
    exclude:
    - '**.md'
    - .devcontainer/*
    - .github/*
    - docs/*
    - LICENSE.TXT
    - PATENTS.TXT
    - THIRD-PARTY-NOTICES.TXT

variables:
  - template: /eng/pipelines/common/variables.yml

schedules:
- cron: "30 2 * * *"
  displayName: Every night at 2:30AM
  branches:
    include:
    - main
  always: true

extends:
  template:  /eng/pipelines/common/templates/pipeline-with-resources.yml
  parameters:
    stages:
    - stage: Build
      jobs:

      - ${{ if and(ne(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'Schedule')) }}:

        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/common/global-build-job.yml
            buildConfig: release
            runtimeFlavor: mono
            runtimeVariant: monointerpreter
            platforms:
            - linux_arm64
            jobParameters:
              nameSuffix: mono
              buildArgs: -s mono+clr.iltools+clr.hosts+libs+host+packs -c $(_BuildConfig)
              isOfficialBuild: false
              postBuildSteps:
              - template: /eng/pipelines/common/upload-artifact-step.yml
                parameters:
                  rootFolder: $(Build.SourcesDirectory)/artifacts/bin
                  includeRootFolder: false
                  archiveType: $(archiveType)
                  archiveExtension: $(archiveExtension)
                  tarCompression: $(tarCompression)
                  artifactName: BuildArtifacts_$(osGroup)$(osSubgroup)_$(archType)_$(_BuildConfig)_mono
                  displayName: Build Assets

        # run arm64 interpreter jobs for mono
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: mono
            platforms:
            - linux_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              runtimeType: mono
              codeGenType: 'Interpreter'
              projectFile: microbenchmarks.proj
              runKind: micro_mono
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              timeoutInMinutes: 720

      - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'Schedule')) }}:

        # build coreclr and libraries
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/common/global-build-job.yml
            buildConfig: release
            platforms:
            - linux_x64
            - windows_x64
            - linux_arm64
            - windows_arm64
            jobParameters:
              nameSuffix: coreclr
              buildArgs: -s clr+libs+host+packs -c $(_BuildConfig)
              isOfficialBuild: false
              postBuildSteps:
              - template: /eng/pipelines/common/upload-artifact-step.yml
                parameters:
                  rootFolder: $(Build.SourcesDirectory)/artifacts/bin
                  includeRootFolder: false
                  archiveType: $(archiveType)
                  archiveExtension: $(archiveExtension)
                  tarCompression: $(tarCompression)
                  artifactName: BuildArtifacts_$(osGroup)$(osSubgroup)_$(archType)_$(_BuildConfig)_coreclr
                  displayName: Build Assets

        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/common/global-build-job.yml
            buildConfig: release
            runtimeFlavor: mono
            runtimeVariant: 'llvmaot'
            platforms:
            - linux_arm64
            jobParameters:
              buildArgs: -s mono+libs+host+packs -c $(_BuildConfig) /p:MonoAOTEnableLLVM=true /p:MonoEnableLLVM=true /p:BuildMonoAOTCrossCompiler=true /p:MonoLibClang="/usr/local/lib/libclang.so.16" /p:AotHostArchitecture=arm64 /p:AotHostOS=linux
              nameSuffix: AOT
              isOfficialBuild: false
              postBuildSteps:
                - template: /eng/pipelines/common/upload-artifact-step.yml
                  parameters:
                    rootFolder: '$(Build.SourcesDirectory)/artifacts/'
                    includeRootFolder: true
                    displayName: AOT Mono Artifacts
                    artifactName: LinuxMonoAOTarm64
                    archiveExtension: '.tar.gz'
                    archiveType: tar
                    tarCompression: gz

        # run mono aot microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml # NOTE: should we move this file out of coreclr tempelates because it contains mono jobs?
            buildConfig: release
            runtimeFlavor: aot
            platforms:
            - linux_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              runtimeType: mono
              codeGenType: 'AOT'
              projectFile: microbenchmarks.proj
              runKind: micro_mono
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              timeoutInMinutes: 780

      # run coreclr Linux arm64 ampere microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - linux_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              timeoutInMinutes: 780

      #run coreclr Linux arm64 ampere no dynamic pgo microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - linux_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              timeoutInMinutes: 780
              pgoRunType: --nodynamicpgo

      #run coreclr Linux arm64 ampere no R2R microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - linux_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              timeoutInMinutes: 780
              r2rRunType: --nor2r

      # run coreclr Windows arm64 microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - windows_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfsurf'

      # run coreclr Windows arm64 ampere microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - windows_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              timeoutInMinutes: 780

      # run coreclr Windows arm64 ampere no dynamic pgo microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - windows_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              pgoRunType: -NoDynamicPGO
              timeoutInMinutes: 780

      # run coreclr Windows arm64 ampere no R2R microbenchmarks perf job
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - windows_arm64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'perfampere'
              r2rRunType: -NoR2R
              timeoutInMinutes: 780

        # run coreclr cloudvm microbenchmarks perf job
        # this run is added temporarily for measuring AVX-512 performance
        - template: /eng/pipelines/common/platform-matrix.yml
          parameters:
            jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
            buildConfig: release
            runtimeFlavor: coreclr
            platforms:
            - linux_x64
            - windows_x64
            jobParameters:
              testGroup: perf
              liveLibrariesBuildConfig: Release
              projectFile: microbenchmarks.proj
              runKind: micro
              runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
              logicalmachine: 'cloudvm'

      # Uncomment once we fix https://github.com/dotnet/performance/issues/1950
      # # run coreclr linux crossgen perf job
      # - template: /eng/pipelines/common/platform-matrix.yml
      #   parameters:
      #     jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
      #     buildConfig: release
      #     runtimeFlavor: coreclr
      #     platforms:
      #     - linux_arm64
      #     jobParameters:
      #       testGroup: perf
      #       liveLibrariesBuildConfig: Release
      #       projectFile: crossgen_perf.proj
      #       runKind: crossgen_scenarios
      #       runJobTemplate: /eng/pipelines/coreclr/templates/run-scenarios-job.yml
      #       logicalmachine: 'perfa64'

      # # run coreclr windows crossgen perf job
      # - template: /eng/pipelines/common/platform-matrix.yml
      #   parameters:
      #     jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
      #     buildConfig: release
      #     runtimeFlavor: coreclr
      #     platforms:
      #     - windows_arm64
      #     jobParameters:
      #       testGroup: perf
      #       liveLibrariesBuildConfig: Release
      #       projectFile: crossgen_perf.proj
      #       runKind: crossgen_scenarios
      #       runJobTemplate: /eng/pipelines/coreclr/templates/run-scenarios-job.yml
      #       logicalmachine: 'perfsurf'
